package com.lsq.tucao.express.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.lsq.tucao.express.bean.po.Notice;
import com.lsq.tucao.express.dao.NoticeMapper;
import com.lsq.tucao.express.response.JsonResult;
import com.lsq.tucao.express.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    /**
     * @author lsq
     * @description 获取所有公告栏数据
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/21 21:52
     */
    @Override
    public JsonResult getAllNotice() {
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        List<Notice> notices = noticeMapper.selectList(queryWrapper);
        if(notices != null && notices.size() == 5){
            return new JsonResult(notices,200,"获取公告栏数据成功");
        }else {
            return new JsonResult(500,"获取公告栏数据失败");
        }
    }

    /**
     * @author lsq
     * @description 修改公告栏数据
     * @param notice
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/21 21:52
     */
    @Override
    public JsonResult updateNotice(Notice notice) {
        if(notice != null){
            int update = noticeMapper.updateById(notice);
            if(update > 0){
                return new JsonResult(200,"公告栏发布成功");
            }else {
                return new JsonResult(500,"公告栏发布失败");
            }

        }else {
            return new JsonResult(500,"请传入公告栏数据");
        }
    }
}
